package com.wlj.web.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.wlj.dto.MenuDTO;
import com.wlj.pojo.TbUser;
import com.wlj.service.MenuService;
import com.wlj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;

@Controller
@RequestMapping("/")
public class IndexController {

    @Autowired
    private MenuService menuService;

    @Autowired
    private UserService userService;

    @GetMapping(value = {
            "",
            "index.html"
    })
    public String index(Model model, Authentication curUser){
        List<MenuDTO> allMenus = menuService.getAllMenus();
        model.addAttribute("menus", allMenus);
        TbUser user = userService.getOne(Wrappers.<TbUser>lambdaQuery().eq(TbUser::getUsername, curUser.getName()));
        model.addAttribute("user",user);
        return "/index";
    }


    @GetMapping(value = {
            "login",
            "login.html"
    })
    public String login(){
        return "/login";
    }


    @GetMapping("home.html")
    public String home(){
        return "/home";
    }
}
